home *** CD-ROM | disk | FTP | other *** search
- Path: prodigy.com!usenet
- From: NEKU72A@prodigy.com (Brian Munroe)
- Newsgroups: comp.lang.c++
- Subject: Help! What's wrong with this?
- Date: 17 Apr 1996 06:26:43 GMT
- Organization: Prodigy Services Company 1-800-PRODIGY
- Distribution: world
- Message-ID: <4l22v3$1beo@useneta1.news.prodigy.com>
- NNTP-Posting-Host: innugap1-int.news.prodigy.com
- X-Newsreader: Version 1.2
-
- I'm trying to learn C++ and I've run into a strange problem in the
- following code.
-
- int const ADD_LEN = 40;
- int main()
- {
- struct cust_list {
- char name[ADD_LEN];
- char add1[ADD_LEN];
- char add2[ADD_LEN];
- char add3[ADD_LEN];
- } customer;
- int flag;
-
- void get_customer_info(char temp[ADD_LEN], int flag);
-
- for (flag=0; flag<4; flag++)
- { switch (flag)
- { case 0: get_customer_info(customer.name, flag); break;
- case 1: get_customer_info(customer.add1, flag); break;
- case 2: get_customer_info(customer.add2, flag); break;
- case 3: get_customer_info(customer.add3, flag); break;
- default: exit(1);
- }
- }
- return 0;
- }
-
- void get_customer_info(char temp[ADD_LEN], int flag)
- { int answer;
- int len;
- clrscr();
- switch (flag)
- { case 0:
- cout << "Enter the bidder's name in one of the following forms.\n";
- cout << " Person: LAST NAME, FIRST NAME\n";
- cout << " Business: COMPANY NAME\n\n";
- break;
- case 1:
- cout << "\nEnter first line of address\n";
- break;
- case 2:
- cout << "\nEnter second line of address\n";
- break;
- case 3:
- cout << "\nEnter third line of address\n";
- break;
- default:
- exit(1);
- }
- cin >> temp;
- len = strlen(temp);
- if (len < ADD_LEN)
- { strncat(temp, " ",ADD_LEN-
- len);}
- temp[ADD_LEN-1] = '\0';
- return;
- }
-
- When I run this all 4 prompts are outputted (Is that a word?), but only
- input for the name and second line are accepted. The input line doesn't
- accept input for the first and third lines. I'm guessing that there is a
- return character caught in the input buffer after I input the name and
- second address lines and it's read in for the first and third lines. If
- so, how do I get it out of the buffer and what the heck is it doing there
- in the first place !?
-
- Thanks for your help.
-
-
-
-